<extend name="Public/frame" />
<block name="content-box">

    <table id="table-grid" class="table table-hover">
        <thead>
        <tr>
            <th data-column-id="uid" data-order="desc" data-type="numeric" data-identifier="true">UID</th>
            <th data-column-id="email" data-sortable="false">邮箱</th>
            <th data-column-id="cellphone" data-sortable="false">手机</th>
            <th data-column-id="username" data-sortable="false">用户名</th>
            <th data-column-id="reg_info" data-sortable="false">注册</th>
            <if condition="access_permit('userhandle') OR access_permit('userview')">
                <th data-column-id="commands" data-formatter="commands" data-sortable="false">{$Think.lang.operation}</th>
            </if>
        </tr>
        </thead>
    </table>

    <script type="text/javascript">
        var popup_dialog = null;
        var grid;
        /*<if condition="access_permit('userhandle')">*/
        var grid_buttons = ['<div class="btn-group">',
            '<a href="{:U(CONTROLLER_NAME.'/userhandle?action=add')}" class="btn btn-default"><span class="glyphicon glyphicon-plus"></span></a>',
            '<a href="javascript:void(0);" onclick="admin_grid_delete(\'{:U(CONTROLLER_NAME.'/userhandle?action=delete')}\');" class="btn btn-default"><span class="glyphicon glyphicon-trash"></span></a>',
            '</div>'].join('');
        /*<else />*/
        var grid_buttons = '';
        /*</if>*/

        function close_dialog(){
            if(popup_dialog){
                popup_dialog.close();
                popup_dialog = null;
            }
        }

        require(['jquery.bootgrid'],function(){
            grid = $("#table-grid").bootgrid({
                    <include file="Public:jstablelist" />
                    url: "{:U(CONTROLLER_NAME.'/userlist')}",

                    formatters: {
                        commands: function(col, row){
                            if(row.id=='1'){
                                return '&nbsp;';
                            }
                            return "<a href='#' class='command-view' title='{$Think.lang.view}' data-row-id='" + row[this.identifier] + "'><span class='glyphicon glyphicon-eye-open'></span></a>&nbsp;&nbsp;&nbsp;&nbsp;" +
                                    "<a href='#' class='command-view' title='{$Think.lang.view}' data-row-id='" + row[this.identifier] + "'><span class='glyphicon glyphicon-pencil'></span></a>&nbsp;&nbsp;&nbsp;&nbsp;" +
                                    "<a href='#' class='command-delete' title='{$Think.lang.delete}' data-row-id='" + row[this.identifier] + "'><span class='glyphicon glyphicon-remove'></span></a>";
                        },

                        status:function(col,row){
                            if(row.status=='1'){
                                return '已订阅';
                            }else if(row.status=='1'){
                                return '已退订';
                            }
                            return '未知';
                        }
                    }
        }).on("loaded.rs.jquery.bootgrid", function(){

                    grid.find(".command-view").on("click", function(e){

                        var url = "{:U(CONTROLLER_NAME.'/userview?id=-id-')}".replace('-id-', $(this).data("row-id") );
                        popup_dialog = $.dialog({content: "url:"+url,height:$(window).height()-50,width:800,lock:true});
                        return false;

                    }).end().find(".command-delete").on("click", function(e){

                        if(confirm('{$Think.lang.delete}?')){
                            admin_grid_delete_one( "{:U(CONTROLLER_NAME.'/userhandle?action=delete')}", $(this).data("row-id"));
                        }
                        return false;

                    });
                });
        });

    </script>

</block>